﻿using LibraryMIS_SE01.BC;
using LibraryMIS_SE01.UC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LibraryMIS_SE01
{
    public partial class MainForm : Form
    {
        bool sideLeftVal = false;//左边导航收缩阈值
        public MainForm()
        {
            InitializeComponent();
            timerRealTime.Start();
            //实例化图书管理用户控件
            BookManagement book = new BookManagement();
            AddUCToPanel(book);

        }
        /// 将控件填充至panelModels中
        private void AddUCToPanel(Control controlName)
        {
            controlName.Dock = DockStyle.Fill;
            panelModels.Controls.Clear();
            panelModels.Controls.Add(controlName);
        }
        #region 关机按钮实现（进入、离开、单击事件）
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            pictureBox1.BackColor = Color.FromArgb(255, 63, 51);
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            pictureBox1.BackColor = Color.FromArgb(65, 82, 98);
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            System.Environment.Exit(0);//彻底退出整个应用程序（进程、io等）
        }
        #endregion

        private void timerRealTime_Tick(object sender, EventArgs e)
        {
            DateTime t = DateTime.Now;//取当前时间
            labelRealTime.Text = t.ToString("HH:MM:ss");//将当前时间赋值给labelRealTime，并进行格式化
            // Tips：需要在构造函数中进行timerRealTime的启动
            //启动代码：timerRealTime.Start();
        }
        /// 光标移动实现
        private void MoveCusor(Control controlName)
        {
            panelCusor.Top = controlName.Top;//做光标控件panelCusor的顶部位置对齐
            panelCusor.Height = controlName.Height;//实现光标控件panelCusor和传入的控件高度一致
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            MoveCusor(btnHome);
        }

        private void btnBookManagement_Click(object sender, EventArgs e)
        {
            MoveCusor(btnBookManagement);
            BookManagement bm = new BookManagement();
            AddUCToPanel(bm);
        }

        private void btnBorrowBook_Click(object sender, EventArgs e)
        {
            MoveCusor(btnBorrowBook);
            BorrowForm bf = new BorrowForm();
            AddUCToPanel(bf);
            bf.Show();
        }

        private void btnReturnBook_Click(object sender, EventArgs e)
        {
            MoveCusor(btnReturnBook);
        }

        private void btnRenewBook_Click(object sender, EventArgs e)
        {
            MoveCusor(btnRenewBook);
        }

        private void btnUsersManagement_Click(object sender, EventArgs e)
        {
            MoveCusor(btnUsersManagement);
        }

        private void btnConfig_Click(object sender, EventArgs e)
        {
            MoveCusor(btnConfig);
        }
        private void btnAboutus_Click(object sender, EventArgs e)
        {
            MoveCusor(btnAboutus);
            AboutUS au = new AboutUS();
            au.ShowDialog();
        }

        #region 左导航缩进实现
        private void timerLeftSide_Tick(object sender, EventArgs e)
        {
            if (sideLeftVal)
            {
                /// 实现左导航向右推开实现
                panelLeft.Width = panelLeft.Width + 5;//15：15px的速率推
                if (panelLeft.Width >= 210)
                {
                    timerLeftSide.Stop();
                    sideLeftVal = false;
                    this.Refresh();
                }
            }
            else
            {
                /// 实现左导航向左推闭实现
                panelLeft.Width = panelLeft.Width - 15;//15：15px的速率推
                if (panelLeft.Width <= 54)
                {
                    timerLeftSide.Stop();
                    sideLeftVal = true;
                    this.Refresh();
                }
            }
        }
        // 单击More图片触发导航缩进
        private void pictureBoxMore_Click(object sender, EventArgs e)
        {
            timerLeftSide.Start();
        }
        #endregion

    }
}
